//
//  PMineStatusViewController.m
//  Btpin
//
//  Created by Vic on 2019/3/23.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "PMineStatusViewController.h"

@interface PMineStatusViewController ()<PSSingleRowViewDelegate>
{
    PSCell *statusCell;
    
    NSString *current;
}
@property (nonatomic, strong) PSSingleRowView *statusPickerView;
@end

@implementation PMineStatusViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    if (self.statusPickerView) {
        self.statusPickerView.hidden = YES;
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"求职状态";
    current = @"";
    
    [self initUI];
}
- (void)initUI {
    UIButton *okBtn = [UIToolsControl initButtonWithFrame:CGRectMake(WIDTH-50*Scale, HeightOfStatusBar+3*Scale, 50*Scale, 36*Scale) imageName:nil target:self action:@selector(okBtnTap) title:@"确定" titleColor:THEMECOLOR_OF_ORANGE];
    okBtn.titleLabel.font = Font(Font_15);
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:okBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
    
    __weak __typeof(self)weakSelf = self;
    self.statusPickerView = [[PSSingleRowView alloc] initWithData:[DataToolsControl sharedManager].allCategoryInfoModel.currentArray target:self];
    self.statusPickerView.hidden = YES;
    
    statusCell = [[PSCell alloc] initWithFrame:CGRectMake(30*Scale, 10*Scale, WIDTH-60*Scale, PSCellHeight) title:@"我的当前状态" text:(UD_GetOForK(isCurrentCn)?UD_GetOForK(isCurrentCn):nil) placeholder:@"请选择" cellType:PSCellTypeOfIndicator];
    statusCell.tap = ^{
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        strongSelf.statusPickerView.hidden = NO;
    };
    [self.view addSubview:statusCell];
    
    return;
    
    UILabel *settingLbl = [UIToolsControl initLabelWithFrame:CGRectMake(StartX(statusCell), EndY(statusCell), ViewWidth(statusCell), 50*Scale) text:@"隐私设置" textColor:THEMECOLOR_OF_TEXT_333333 font:Font_13];
    [self.view addSubview:settingLbl];
    [settingLbl borderColor:THEMECOLOR_OF_TEXT_cccccc borderWidth:lineH borderType:BorderSideTypeBottom];
    UIImageView *imgView = [UIToolsControl initImageViewWithFrame:CGRectMake(ViewWidth(statusCell)-8*Scale, 18*Scale, 7*Scale, 13*Scale) imageName:@"jiantou_right"];
    [settingLbl addSubview:imgView];
    UIButton *settingBtn = [UIToolsControl initButtonWithFrame:settingLbl.bounds imageName:nil target:self action:@selector(settingBtnTap) title:nil titleColor:nil];
    [settingLbl addSubview:settingBtn];
}
- (void)okBtnTap {
    NSLog(@"确定");
    if (statusCell.textField.text.length) {
        [self upDate];
    } else {
        SVPHUDError(PStatusOKAlertText);
        [statusCell.textField becomeFirstResponder];
    }
}
- (void)upDate {
    self.noDataView.hidden = YES;
    SVPHUDShow;
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:0];
    dic = [UIToolsControl getPublicParameter];
    [dic setObject:(UD_GetOForK(isResumeID)?UD_GetOForK(isResumeID):@"") forKey:@"resume_id"];
    [dic setObject:current forKey:@"current"];
    
    [BaseNetManager requestWithMethod:POST path:Person_SetCurrent_URL params:dic successBlock:^(NSDictionary * _Nonnull responseObject) {
        if ([responseObject[@"code"] integerValue] == 2000) {
            SVPHUDSuccess(responseObject[@"msg"]);
            UD_SetOForK(self->statusCell.textField.text, isCurrentCn);
            
            self.setback(YES);
            [self performSelector:@selector(delayClick) withObject:nil afterDelay:0.5];
        } else {
            SVPHUDError(responseObject[@"msg"]);
        }
    } failurBlock:^(NSError * _Nonnull error) {
        SVPHUDError(NetErrorAlertText);
        [self.noDataView vcNilStatusType:VCNilStatusTypeOfNoNet superView:self.view];
    }];
}
- (void)delayClick {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)settingBtnTap {
    NSLog(@"隐私设置");
}
- (void)psSingleRowViewCancel:(PSSingleRowView *)psSingleRowView {
    psSingleRowView.hidden = YES;
}
- (void)psSingleRowViewOk:(PublicCategoryElementModel *)model PSSingleRowView:(PSSingleRowView *)psSingleRowView {
    psSingleRowView.hidden = YES;
    statusCell.textField.text = model.name;
    current = model.id;
}

@end
